package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.GoodsParamMapper;
import com.weixing.mall.provider.model.domain.GoodsParam;
import com.weixing.mall.provider.model.dto.GoodsParamDto;
import com.weixing.mall.provider.model.vo.GoodsParamVo;
import com.weixing.mall.provider.service.IGoodsParamService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wx
 * @Date 2019/8/12 15:56
 * @Version 1.0
 */
/**
 * <p>
 * 商品模块-商品参数 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class GoodsParamServiceImpl extends ServiceImpl<GoodsParamMapper, GoodsParam> implements IGoodsParamService {

    @Autowired
    private GoodsParamMapper goodsParamMapper;
    @Override
    public void save(List<GoodsParamDto> list,Long goodsId) {

        GoodsParam goodsParam = new GoodsParam();
        goodsParamMapper.deleteByGoodsId(goodsId);
        if(!list.isEmpty()){
            for (GoodsParamDto goodsParamDto : list) {
                BeanUtils.copyProperties(goodsParamDto,goodsParam);
                goodsParam.setGoodsId(goodsId);
                save(goodsParam);
            }
        }
    }
    @Override
    public List<GoodsParamVo> selectByGoodsId(Long goodsId) {
        return goodsParamMapper.selectByGoodsId(goodsId);
    }
}
